package ThreadPool.jike.demo07;

/**
 * @param
 * @author oyz
 * @version 1.1.0
 * @description: TODO
 * @date 2022-8-23 14:01
 */
public class DataRaceTest2 {

    private static int count = 0;


    // private static volatile DataRaceTest2 dataRaceTest2 = new DataRaceTest2();

    static synchronized void set(int i){
        count = i;
    }

    static synchronized int get(){
        return count;
    }

    static void add(){
       int id = 0;
       while(id<=10000){
           set(get()+1);
       }
    }

    public static void main(String[] args) throws InterruptedException {
        new Thread(()->{
            add();
        }).start();
       /* new Thread(()->{
            add();
        }).start();*/
        Thread.sleep(2000);
        System.out.println(count);
    }
}
